#include <stc8h.h>
#include "uart1.h"
#include "stdio.h"
#include "RTC1.h"
#include <intrins.h>
#include "timer0.h"
#include "adc1.h"

#define VERF (*(unsigned int volatile xdata *)0xfde7)

void downpower(int ms){
	// f=36425
    int t;
    t=(int)(ms*2.2766-1);
    WKTCL=t&0xff;
    WKTCH=(t>>8)+0x80;
    UartSend(t&0xff);
    UartSend(t>>8);
    NOP3();
    PCON=PD;
    NOP3();  

}
void Delay10us(void)	//@22.1184MHz
{
	unsigned char data i;

	_nop_();
	_nop_();
	i = 71;
	while (--i);
}
void Delay1ms(void)	//@22.1184MHz
{
	unsigned char data i, j;

	i = 29;
	j = 183;
	do
	{
		while (--j);
	} while (--i);
}
void Delay500ms(void)	//@22.1184MHz
{
	unsigned char data i, j, k;

	i = 57;
	j = 27;
	k = 112;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}
void Delay10ms(void)	//@22.1184MHz
{
	unsigned char data i, j, k;

	i = 2;
	j = 32;
	k = 60;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Delay50ms(void)	//@22.1184MHz
{
	unsigned char data i, j, k;

	_nop_();
	i = 6;
	j = 157;
	k = 59;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}



void main(void)
{       
	//0xfde7
	int* p=0xfde7;

	unsigned char xdata  *BGV;
	BGV =(unsigned char xdata *)0xfde7;   
    P0M0 = 0x00; P0M1 = 0x00; 
    P1M0 = 0x00; P1M1 = 0x00; 
    P2M0 = 0x00; P2M1 = 0x00; 
    P3M0 = 0x00; P3M1 = 0x00; 
    P4M0 = 0x00; P4M1 = 0x00; 
    P5M0 = 0x00; P5M1 = 0x00; 
    P6M0 = 0x00; P6M1 = 0x00; 
    P7M0 = 0x00; P7M1 = 0x00; 


	P5PU |= 0x10; //P54上拉


    P_SW2 |= 0x80;   //使能XFR访问

    RTC_init();
    lcd_init();
    Uart1_Init();
    Timer0_Init();
	ADCInit();
    printf("start!!!");
	Delay50ms();
	ADCRead();
	setvlcd(ADCRead());
	showm();
	P34=1;
	// printf("%d",*BGV);
    while (1)
    {
        while (showsec(0));

		// ADCRead();
        NOP3();
        PCON=PD;
        NOP3();
        
    }
}

